package listener;

import event.EmailEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

/**
 * 测试Spring的事件机制，容器事件的监听器需要实现ApplicationListener接口
 */
public class EmailListener implements ApplicationListener{
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (applicationEvent instanceof EmailEvent){
            EmailEvent emailEvent = (EmailEvent) applicationEvent;
            System.out.println("监听到EmailEvent事件 "
                    +emailEvent.getAddress()+", "
                    +emailEvent.getText());
            System.out.println(emailEvent);
        }else{
            System.out.println(applicationEvent);
        }
    }
}
